Skip to content

BUG: Timestamp.round precision error for ns (#15578) #15588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mroeschke
Copy link
Member

Nice trick @jreback! round() patched for DatetimeIndex and Timestamp when rounding by ns.

@codecov-io
Copy link

codecov-io commented Mar 6, 2017

Codecov Report

Merging #15588 into master will decrease coverage by -0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master   #15588      +/-   ##
==========================================
- Coverage   91.06%   91.04%   -0.02%     
==========================================
  Files         137      137              
  Lines       49307    49315       +8     
==========================================
- Hits        44899    44897       -2     
- Misses       4408     4418      +10
Impacted Files Coverage Δ
pandas/tseries/base.py 96.65% <100%> (+0.06%)
pandas/io/gbq.py 25% <0%> (-58.34%)
pandas/tools/merge.py 91.78% <0%> (-0.35%)
pandas/core/frame.py 97.83% <0%> (-0.1%)
pandas/tseries/index.py 95.42% <0%> (+0.09%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7740231...af95baa. Read the comment docs.

pandas/tslib.pyx Outdated
if self.tz is not None:
value = self.tz_localize(None).value
else:
value = self.value
result = (unit * rounder(value / float(unit)).astype('i8'))
if time_unit == 'N':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this way I think you want to deal with offset.nanos < 1000 and offset.nanos % 1000 != 0.

This then would have an error case if offset.nanos >= 1000 and offset.nanos % 1000 != 0

# ok!
In [11]: to_offset('1D').nanos % 1000
Out[11]: 0

# ok
In [12]: to_offset('10ms').nanos % 1000
Out[12]: 0

# ok
In [13]: to_offset('10us').nanos % 1000
Out[13]: 0

# ok (with the separate rounding)
In [14]: to_offset('10ns').nanos % 1000
Out[14]: 10

# NOT OK, this we would lose precision on! raise!
In [15]: to_offset('1010ns').nanos % 1000
Out[15]: 10

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, this method makes more sense. Thanks!

I mistakenly thought .nanos returned the numeric value after the time unit instead of the frequency in nanoseconds which is why I was using this method.

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Datetime Datetime data dtype labels Mar 6, 2017
@mroeschke
Copy link
Member Author

Altered the logic and now will raise a warning for an invalid frequency like 1010ns

@jreback jreback closed this in fdee922 Mar 7, 2017
@jreback jreback added this to the 0.20.0 milestone Mar 7, 2017
@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

thanks @mroeschke

keep em coming!

AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
closes pandas-dev#15578

Author: Matt Roeschke <[email protected]>

Closes pandas-dev#15588 from mroeschke/fix_15578 and squashes the following commits:

af95baa [Matt Roeschke] BUG: Timestamp.round precision error for ns (pandas-dev#15578)
@mroeschke mroeschke deleted the fix_15578 branch December 20, 2017 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timestamp .round precision for ns
3 participants